package com.song.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.song.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author TonySong
 * @date 2024/5/10 0010
 * @time 9:32
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Resource
    private OrderService orderService;

   // @SentinelResource(blockHandler = "blockOrder",fallback = "fallbackOrder")
    @GetMapping("/addOrder")
    public String order(){
        return "下单成功！";
    }

   // @SentinelResource(blockHandler = "blockOrder",fallback = "fallbackOrder")
    @GetMapping("/getOrder")
    public String getOrder(){
        return "查询订单";
    }

   // @SentinelResource(blockHandler = "blockOrder",fallback = "fallbackOrder")
    @GetMapping("/test1")
    public String test1() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        return "线程的测试";
    }

    @GetMapping("/show1")
    public String show1(){
         return this.orderService.showOrder();
    }
    @GetMapping("/show2")
    public String show2(){
        return this.orderService.showOrder();
    }
//    public String blockOrder(BlockException e) {
//       return  "block 流控";
//    }
//
//    public String fallbackOrder(){
//        return "QPS too high, please try again later!";
//    }
}
